package com.multi.thread.chapter01;

public class StopByExceptionThread extends Thread {

	@Override
	public void run() {
		try {
			for (int i = 0; i < 1000000; i++) {
				if (Thread.interrupted()) {
					System.out.println("已经是停止状态，我要退出了!");
						throw new InterruptedException();
				}
				System.out.println("i = " + (i + 1));
			}
		} catch (InterruptedException e) {
			System.out.println("进入catch！");
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) throws InterruptedException {
		StopByExceptionThread thread = new StopByExceptionThread();
		thread.start();
		Thread.sleep(2000);
		thread.interrupt();
	}

}
